/**
 * @author ciwyaitd
 * @author levy 重构为新的api
 * @date   16/1/13
 * @description [ 大部分组件在processDetail.js ]
 * @desc [ 页面根据传入不同status来进行渲染 ]
 */
import DetailInfo from "../components/detail/ImgTextDetail";
import FooterBtn from "../components/detail/FooterBtn";
import BottomForm from "../components/detail/BottomForm";
import PersonSelectCon from "../components/detail/SelectPerson";
import LargeImgLayer from "../components/LargeImg";
import {health} from "../const/offices";
import {prefix} from "../const/prefix";

import {
    TaskProcessDetail,
    DoneTaskDetailLayer,
    LayerTextCon,
    FormContentSend,
    FormContentDeal,
    FormContentReview
    } from "../components/detail/processDetail";

liefeng.bridgeJs.bridgeReady(function ( lf, r) {

    var RC = r.createClass,
        utils = lf.utils,
        bridge = lf.bridgeJs,
        ajax = utils.ajax,
        api = health.api,
        apiUrl = prefix.oldpeople,
        getUrlParam = utils.getUrlParam,
        registerHandler = bridge.registerHandler,
        getUser = bridge.getUser,
        selectPhoto = bridge.selectPhoto,
        appAlert = bridge.alert,
        appConfirm = bridge.confirm,
        uploadImg = bridge.uploadImg,
        oldId = getUrlParam('oldId'),//上一个页面新接口拿到的员工id
        flag = getUrlParam('flag', location.search) || '';

    var tableTitList = [
            [ 'content', '任务描述'],
            [ 'location', '服务地点'],
            [ 'reporterName', ' 联 系 人 '],
            [ 'phone', '联系电话'],
            [ 'orderTime', '预约时间']
        ],
        orderId = getUrlParam('orderId'),
        taskStatus = {
            distributeLeaflets: '派单',
            dispatching: '派工',
            handle: '办理',
            audit: '领导审核',
            returnVisit: '客服回访',
        };

    /*------------------ 公共 ------------------*/
    var TaskProcessCon = RC({
        getInitialState: function () {
            return {
                status: '',//当前步骤	 /派工/办理/领导审核/客服回访 //前四个有退回，自己指给别人的单可撤回
                allDt: '',
                currTask: '', //当前工单
                taskList: '', //工单处理步骤集合
                latestWfTaskId:'',//最新的wfTaskId, 妈的，我是被逼这样做的。
                largeImgSrc: '',
                largeImgVisible: '',
                footerBtnVisible: '',
                recallBtnVisible: '',
                reviewBtnVisible: 'ele-hide',
                formVisible: '',
                formConVisible: '',
                layerVisible: '',
                layerConVisible: '',
                selectVisible: '', // 选择遮罩层
                selectConVisible: '', // 选择弹出层
                reviewerVisible: '',
                reviewerConVisible: '',
                layerCon: {},
                taskProcessData: this.props.dt.eventProcessList || '',
                selectForm: [], // 选择人的表单层
                helperSelectId: '', // 协助人id
                reviewerSelectId: '', // 审批人id
                taskLayerList: [], // 弹出层的标题列
                focusFlag: 1, // 光标是否focus在textarea上
                dealImgList: [] // 办理选中的图片
            }
        },
        componentWillMount: function () {
            var props = this.props,
                eventList = props.dt.eventProcessList,
                currTask = eventList[eventList.length - 1],
                status = currTask.taskDisplayName;//中文来的

            liefeng.taskInfo.eventId = props.dt.id;


            this.setState({
                allDt: props.dt,
                currTask: currTask,
                status: status,
                taskList: eventList,
            });
        },
        render: function () {
            var state = this.state,
                footerBtn = this.footerBtnRender(),
                bottomForm = this.bottomFormRender();
            //log(state.allDt)
            //log(state.currTask)

            return (
                <div>
                    <DetailInfo data={this.state.allDt}
                                tableTitList={tableTitList}
                                enlargeHandler={this._enlargeHandler}
                                title={this.props.title} />
                    <TaskProcessDetail  status={this.state.status} data={this.state.allDt} taskLayerRender={this.taskLayerRender} />
                    {footerBtn} {bottomForm}
                    <DoneTaskDetailLayer
                        displayNone={this._hideBottomForm}
                        layerConRender={this.layerConRender}
                        layerCon={state.layerCon}
                        layerVisible={state.layerVisible}
                        layerConVisible={state.layerConVisible}/>
                    <LargeImgLayer imgSrc={this.state.largeImgSrc}
                                   hideHandler={this._hideHandler}
                                   visible={this.state.largeImgVisible}/>
                </div>
            )
        },

        _enlargeHandler: function ( imgSrc ) {
            this.setState({
                largeImgSrc: imgSrc,
                largeImgVisible: 'this'
            });
        },
        _hideHandler: function () {
            this.setState({
                largeImgVisible: ''
            });
        },
        //levy “已处理/已审核/已回访” 点击触发事件
        taskLayerRender: function (index) {
            let data = this.state.taskProcessData[index],
                taskName = data.taskDisplayName;
            //console.log(data);
            var taskLayerList = [];

            if (taskName == '办理') {
                taskLayerList = [
                    ['consumptions', '领取/使用材料'],
                    ['result', '处理结果'],
                    ['assistAccepterName', '协助办理人'],
                    ['picUrls', '图片']
                ];
            }
            else if (taskName.indexOf('审核') > -1) {
                taskLayerList = [
                    ['result','审核意见']
                ];
            }
            else if(taskName.indexOf('回访') > -1){
                taskLayerList = [
                    ['timeliness','服务及时性'],
                    ['level','服务水准'],
                    ['attitude','服务态度'],
                    ['revisitMode','回访方式'],
                    ['result','回访结果'],
                    ['attachs', '图片']
                ];
            }
            //else if ( type && type == 4 ) {
            //	taskLayerList = [
            //		['tit','状态'],
            //		['content','驳回原因']
            //	];
            //	dt = {
            //		tit: '已驳回',
            //		//content: data
            //	}
            //}
            this.setState({
                layerVisible:'this',
                layerConVisible:'this',
                layerCon: data,
                taskLayerList: taskLayerList
            });
        },
        //上面函数改变的state引起这里的重新渲染
        layerConRender: function () {
            return (
                <LayerTextCon data={this.state.layerCon}
                              enlargeHandler={this._enlargeHandler}
                              tableTitList={this.state.taskLayerList} />
            )
        },
        //status 1:退回/派工,2:退回/办理,3:退回/审核,4:撤回,0:没有按钮 status={data.status}

        //levy 底部按钮
        footerBtnRender: function () {
            var status = this.state.status,
                footerBtn = [
                    {aLinkClass: 'red', clickHandler: this._Cancel, text: '退回'},
                    {aLinkClass: 'green', clickHandler: this._Confirm, text: status == '领导审核' ? '审核' : status }
                ],
                recallBtn = [{aLinkClass: 'red', clickHandler: this._recallBtn, text: '撤回'}];

            console.log(status+'status')
            //待签收,没按钮,签收不在流程里,已办结的也没有按钮
            //流转中全不出现按钮
            if(flag == lf.taskInfo.FLOWING || this.state.currTask.status == 0 || this.state.currTask.status == 3){
                return <div></div>
            }
            else if ( status == '撤回' ) {
                return <FooterBtn visiable={this.state.recallBtnVisible} data={recallBtn} />;
            }
            else if (status == taskStatus.distributeLeaflets) {
                console.log('haha')
                return <FooterBtn visiable={this.state.footerBtnVisible}
                                  data={[{aLinkClass: 'green', clickHandler: this._Confirm, text: '派单' }]} />;
            }
            else if ( status == taskStatus.dispatching || status == taskStatus.handle || status == taskStatus.audit ) {
                return  [/*<FooterBtn visiable={this.state.recallBtnVisible} data={recallBtn} />,*///撤回按钮
                    <FooterBtn visiable={this.state.footerBtnVisible} data={footerBtn} />];
            }

        },
        bottomFormRender: function () {
            // 这是下部弹出层的外框, 具体渲染出来的内容在 itemRender
            var status = this.state.status,
            //发送请求的确定按钮
                formFooterBtn = [
                    {aLinkClass: 'red', clickHandler: this._formCancel, text: '取消'},
                    {aLinkClass: 'green', clickHandler: this._formConfirm, text: '确定'}
                ],
                selectFooterBtn = [
                    {aLinkClass: 'red', clickHandler: this._selectCancel, text: '取消'},
                    {aLinkClass: 'green', clickHandler: this._selectConfirm, text: '确定'}
                ],
                formTit = '';// status == 1 ? '执行人' : status == 2 ? '领取/使用材料' : '';

            if ( status == taskStatus.dispatching || status == taskStatus.distributeLeaflets) {
                formTit = '执行人';
                return (
                    <BottomForm
                        itemRender={this.itemRender}
                        formTit={formTit}
                        displayNone={this._hideBottomForm}
                        formFooterBtn={formFooterBtn}
                        formVisible={this.state.formVisible}
                        formConVisible={this.state.formConVisible}
                        onBlurHandler={this._onBlurHandler}
                        />
                )
            }
            else if ( status == taskStatus.handle ) {
                formTit = '领取/使用材料';
                var helperTit = '协助办理人',
                    reviewerTit = '审批人';
                return (
                    [
                        <BottomForm
                            itemRender={this.itemRender}
                            formTit={formTit}
                            displayNone={this._hideBottomForm}
                            formFooterBtn={formFooterBtn}
                            formVisible={this.state.formVisible}
                            formConVisible={this.state.formConVisible}
                            onBlurHandler={this._onBlurHandler}
                            />,
                        <BottomForm
                            itemRender={this.selectConRender}
                            formTit={helperTit}
                            displayNone={this._hideBottomForm}
                            belong="helper"
                            formCon="helper"
                            formFooterBtn={selectFooterBtn}
                            formVisible={this.state.selectVisible}
                            formConVisible={this.state.selectConVisible}
                            />,
                        <BottomForm
                            itemRender={this.selectConRender}
                            formTit={reviewerTit}
                            displayNone={this._hideBottomForm}
                            belong="reviewer"
                            formCon="reviewer"
                            formFooterBtn={selectFooterBtn}
                            formVisible={this.state.reviewerVisible}
                            formConVisible={this.state.reviewerConVisible}
                            />
                    ]
                )
            }
            else if ( status == taskStatus.audit ) {
                formTit = '审核';
                var reviewerTit = '下一级办理人';
                return (
                    [<BottomForm
                        itemRender={this.itemRender}
                        formTit={formTit}
                        displayNone={this._hideBottomForm}
                        formFooterBtn={formFooterBtn}
                        formVisible={this.state.formVisible}
                        formConVisible={this.state.formConVisible}
                        onBlurHandler={this._onBlurHandler}
                        />,<BottomForm
                        itemRender={this.selectConRender}
                        formTit={reviewerTit}
                        displayNone={this._hideBottomForm}
                        belong="dealer"
                        formCon="dealer"
                        formFooterBtn={selectFooterBtn}
                        formVisible={this.state.reviewerVisible}
                        formConVisible={this.state.reviewerConVisible}
                        />]
                )
            }

        },
        selectConRender: function ( data ) {
            if ( data == 'helper') {
                return (
                    <PersonSelectCon maxCount="3" selectClass="J_select_helper" type="helper" />
                )
            }
            else if( data == 'reviewer' ) {
                return (
                    <PersonSelectCon addClass="no-department" selectClass="J_select_reviewer" type="auditor" projectId={this.state.allDt.projectId} />
                )
            }
            else if ( data == 'dealer' ) {
                return (
                    <PersonSelectCon selectClass="J_select_reviewer" type="dealer" currTask={this.state.currTask} />
                )
            }

        },
        // 弹出层渲染
        itemRender: function ( data ) {
            var status = this.state.status;
            //alert(this.state.allDt.projectId)
            if ( status == taskStatus.dispatching ) {//派工
                return (
                    <FormContentSend staffId={ oldId/*lf.userInfo.id*/} projectId={this.state.allDt.projectId}
                                     setFocusFlagHandler={this._setFocusFlagHandler} />
                );
            }
            //派单
            else if (status == taskStatus.distributeLeaflets) {
                return <PersonSelectCon addClass="no-department" type="auditor" projectId={this.state.allDt.projectId}/>;
            }
            //办理
            else if ( status == taskStatus.handle ) {

                var blockBtns = [
                    {tit: '协助处理人',default: '限3人',selectHandler:this._selectHandler},
                    {tit: '审批人',default: '',selectHandler:this._selectHandler,selectFlag:'reviewer'}
                ];

                return (
                    <FormContentDeal upLoadHandler={this._upLoadHandler}
                                     deleteFn={this.deleteImg}
                                     setFocusFlagHandler={this._setFocusFlagHandler}
                                     blockBtns={blockBtns}
                                     currTask={this.state.currTask}
                                     orderId={orderId}
                                     enlargeHandler={this._enlargeHandler}
                                     imgList={this.state.dealImgList} />
                )
            }
            //审核
            else if ( status == taskStatus.audit ) {
                var blockBtns = {
                    tit: '下一级办理人',
                    default: '',
                    selectHandler:this._selectHandler,
                    method:'workInfoAction!findNextWorker.action',
                    selectFlag:'reviewer'
                };
                return (
                    <FormContentReview setFocusFlagHandler={this._setFocusFlagHandler}
                                       currTask={this.state.currTask}
                                       blockBtns={blockBtns}
                                       orderId={orderId}  />
                )
            }

        },
        // 确定按钮,显示弹出层
        _Confirm: function () {
            var me = this;
            me.setState({
                formVisible: 'this',
                formConVisible: 'this'
            });
        },

        // 取消按钮
        _Cancel: function () {
            var me = this,
                sendBack = function(){
                    ajax({
                        url: apiUrl + api.sendBack,
                        type:'POST',
                        data: {
                            staffid: oldId,//lf.userInfo.id, /上一个页面
                            wfTaskId: lf.taskInfo.wfTaskId,
                        },
                        headers: {
                            openId:getUrlParam('openId'),
                        },
                        beforeSend: function () {
                            lf.bridgeJs.doLoading(true);
                        }
                    } ,function cb ( data ) {
                            lf.bridgeJs.doLoading(false);
                            var url = lf.utils.appendParam(location.href, 'flag', lf.taskInfo.FLOWING);
                            location.href = url;
                        })
                };

            appConfirm('你要退回工单信息吗?', sendBack);
            //TODO 成功后，把下面的代码删除
            //appConfirm({
            //   content: '?',
            //   yesFn: 'sendbackYes'
            //});
            //
            //if(lf.utils.getEnv() == 'pc'){
            //	sendBack();
            //}else{
            //	registerHandler({
            //		sendbackYes: function () {
            //			sendBack();
            //		}
            //	});
            //}

        },
        //确定按钮,发送请求request: levy
        _formConfirm: function ( event ) {

            var me = this,
                status = me.state.status,
                $bottom_form = $('.J_bottom_form');

            // 派工/派单确定
            if ( status == taskStatus.dispatching || status == taskStatus.distributeLeaflets) {
                var choose_item = '',
                    send_desc = '',
                    send_id = '',
                    grab = 0;
                    api = apiUrl + api.execute;//lf.api.task.execute;

                if(status == taskStatus.dispatching) {
                    send_desc = $($bottom_form[0]).find('textarea').val();
                    choose_item = $($bottom_form[0]).find('.choose');
                }
                //派单
                else {
                    choose_item = $('.bottom-form-layout.this').find('.choose');
                    api = apiUrl + api.distributeLeaflets,//lf.api.task.distributeLeaflets;
                    appAlert('提交成功');
                }

                if ( choose_item.size() == 0 ) {
                    event.stopPropagation();
                    appAlert('请选择一位人员!');
                    return ;
                }
                //是否抢单
                if(choose_item.size() > 1){
                    grab = 1;
                }
                choose_item.map(function ( i, item ) {
                    var selectedId = $(item).data('id');
                    if ( i > 0 ) {
                        selectedId = ',' + selectedId;
                    }
                    send_id += selectedId;
                });
                //console.log(send_id);

                ajax({
                    type: api,
                    type: 'POST',
                    contentType:'application/x-www-form-urlencoded; charset=UTF-8',
                    data: {
                        //公共参数
                        nextAccepterId: send_id, //下一下办理人，

                        //派工
                        id:lf.taskInfo.id,
                        eventId:lf.taskInfo.eventId,
                        wfTaskId:lf.taskInfo.wfTaskId,
                        currAccepterId: lf.userInfo.id, //当前办理人就是自己
                        grab: grab,
                        result: send_desc,

                        //派单
                        orderId: orderId,
                        staffId: oldId,// lf.userInfo.id,
                    },
                    headers: {
                        openId:getUrlParam('openId'),
                    },
                    beforeSend: function () {
                        lf.bridgeJs.doLoading(true);
                    }
                },function cb ( ) {

                    me._updateTaskProcess(function ( dt ) {
                        //log(dt)
                        me.updateStateByLevy(me,dt);
                        setTimeout(function() {
                            me.setState({
                                formVisible: ''
                            })
                        }, 500);
                    });
                }, function () {
                    lf.bridgeJs.doLoading(false);
                });
            }
            else if ( status == taskStatus.handle ) { // 办理确定
                var $helper = $('.block-link'),
                    $reviewer = $('.reviewer'),
                    deal_result = $('#dealResult').val(),
                    metairl = $('#material').val(),
                    next_worker_id = $reviewer.data('selectid'),
                    $imgContainer = $('.bottom-form-handle-img .swiper-slide'),
                    apeople_id = $helper.data('selectid'),
                    img_ary = [], img_src = '';

                if ( $imgContainer.length != 1
                    || $($imgContainer[0]).find('img').attr('src').indexOf('none') == -1 ) {
                    $imgContainer.each( function ( i, v ) {
                        var src = $(v).find('img').attr('src');
                        img_ary.push(src);
                    });
                    img_src = img_ary.join(',');
                }
                lf.bridgeJs.doLoading(true);
                uploadImg( img_src, function ( imgSrc ) {
                    ajax({
                        url: apiUrl + api.execute,
                        type: 'POST',
                        contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
                        data: {
                            id: lf.taskInfo.id,
                            eventId: lf.taskInfo.eventId,
                            wfTaskId: lf.taskInfo.wfTaskId,
                            currAccepterId: lf.userInfo.id, //当前办理人就是自己
                            nextAccepterId: next_worker_id, //下一下办理人
                            assistAccepterIds: apeople_id,
                            picUrls: imgSrc || '',

                            //orderId: orderId,
                            result: deal_result,
                            consumptions: metairl
                        },
                        headers: {
                            openId:getUrlParam('openId'),
                        },
                    }, function (data) {
                        me._updateTaskProcess(function (dt) {
                            //log(dt)
                            me.updateStateByLevy(me, dt);
                            //me.setState({
                            //   loadingStatus: 'none',
                            //   formConVisible: '',
                            //   footerBtnVisible: 'ele-hide',
                            //   taskProcessData: dt.eventProcessList
                            //});
                            setTimeout(function () {
                                me.setState({
                                    formVisible: ''
                                });
                            }, 500);
                        });
                    } ,function(){
                        lf.bridgeJs.doLoading(false);
                    });
                    },function () {
                        appAlert('图片上传失败!');
                        lf.bridgeJs.doLoading(false);
                    });
            }
            else if ( status == taskStatus.audit ) {// 审核确定
                var check_flag = $('.J_review_radio').find(':checked').data('flag'),
                    review_content = $('#review-content').val(),
                    next_id = $('.reviewer').data('selectid'),
                    auditStatus = check_flag == 'pass' ? 1 : 0;

                if ( review_content == '' ) {
                    appAlert('意见填写不能为空!');
                    return ;
                }

                ajax({
                    url: apiUrl + api.execute,
                    type: 'POST',
                    contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
                    data: {
                        id: lf.taskInfo.id,
                        eventId: lf.taskInfo.eventId,
                        wfTaskId: lf.taskInfo.wfTaskId,
                        currAccepterId: lf.userInfo.id, //当前办理人就是自己
                        nextAccepterId: next_id, //下一下办理人
                        auditStatus: auditStatus,
                        result: review_content,
                    },
                    headers: {
                        openId:getUrlParam('openId'),
                    },
                },function (data) {
                    me._updateTaskProcess(function (dt) {
                        //log(dt)
                        me.updateStateByLevy(me, dt);
                        //me.setState({
                        //	loadingStatus: 'none',
                        //	formConVisible: '',
                        //	footerBtnVisible: 'ele-hide',
                        //	taskProcessData: dt.eventProcessList,//TODO 这个state属性是用到干嘛的
                        //});
                        setTimeout(function () {
                            me.setState({
                                formVisible: ''
                            });
                        }, 500);
                    });
                },function(){
                    lf.bridgeJs.doLoading(false);
                });
            }
        },
        _formCancel: function () {
            var me = this;
            me.setState({
                formConVisible: ''
            });
            setTimeout(function() {
                me.setState({
                    formVisible: ''
                })
            }, 500);
        },
        _recallBtn: function () {
            var me = this,
                status = me.state.status;
            appConfirm({
                content: '你要撤回工单信息吗？',
                yesFn: 'recallYes'
            });

            var recall = function(){
                ajax({
                        url: apiUrl + api. withdraw,
                        type: 'POST',
                        data: {
                            staffid: oldId,
                            wfTaskId: me.state.latestWfTaskId,
                        },
                        headers: {
                             openId:getUrlParam('openId'),
                         },
                        beforeSend: function () {
                            lf.bridgeJs.doLoading(true);
                        },
                        success: function (data) {
                            lf.bridgeJs.doLoading(false);
                            if(data.code == '200'){
                                //返回列表页
                                lf.bridgeJs.doLocation('task-processing-oa.html', '工单处理');
                            }
                            else{
                                appAlert('没有撤回的工单,可能被下一办理人签收了。', function () {
                                    window.location.reload();
                                })
                            }
                        }

                    });
            };

            if(lf.utils.getEnv() == 'pc'){
                recall();
            }else{
                registerHandler({
                    recallYes:function () {
                        recall();
                    }
                });
            }

        },
        _selectConfirm: function ( e, selectFlag) { // 选择层的确定按钮
            var $select_container = $('.J_select_helper'),
                $select_target = $('.block-link'),
                choose_item,select_id='',select_name='';
            if ( selectFlag == 'reviewer' || selectFlag == 'dealer' ) {
                $select_container = $('.J_select_reviewer');
                $select_target = $('.reviewer');
            }

            choose_item = $($select_container[0]).find('.choose');
            if ( choose_item.size() == 0 ) {
                event.stopPropagation();
                appAlert('人员选择不能为空!');
                return ;
            }
            if ( choose_item.size() > 1 ) {
                choose_item.map(function ( i, item ) {
                    var selectedId = $(item).data('id'),
                        selectedName = $(item).text();
                    if ( i > 0 ) {
                        selectedId = ',' + selectedId;
                        selectedName = ',' + selectedName;
                    }
                    select_id += selectedId;
                    select_name += selectedName;
                });
            }
            else {
                select_id = choose_item.data('id');
                select_name = choose_item.text();
            }
            $select_target.attr('data-selectid',select_id);
            $select_target.find('.text-before-arrow').text(select_name);

            if ( selectFlag == 'reviewer' || selectFlag == 'dealer' ) {
                this.setState({
                    reviewerConVisible: ''
                });
                setTimeout(function() {
                    this.setState({
                        reviewerVisible: ''
                    })
                }.bind(this), 500);
                return ;
            }
            this.setState({
                selectConVisible: ''
            });
            setTimeout(function() {
                this.setState({
                    selectVisible: ''
                })
            }.bind(this), 500);
        },
        _selectCancel: function ( e, selectFlag) {
            var me = this;
            if ( selectFlag == 'reviewer' || selectFlag == 'dealer' ) {
                me.setState({
                    reviewerConVisible: ''
                });
                setTimeout(function() {
                    me.setState({
                        reviewerVisible: ''
                    })
                }, 500);
                return ;
            }
            me.setState({
                selectConVisible: ''
            });
            setTimeout(function() {
                me.setState({
                    selectVisible: ''
                })
            }, 500);
        },
        _selectHandler: function ( selectFlag ) {
            // selectFlag 的命名方式 与该组件的visible挂钩
            // 显示选人的层
            if ( selectFlag ) {
                var select_state = selectFlag == 'reviewer' ?
                {reviewerVisible:'this',reviewerConVisible:'this'} : {};
                this.setState( select_state );
                return ;
            }

            this.setState({
                selectVisible: 'this',
                selectConVisible: 'this'
            });
        },
        _upLoadHandler: function (e) {
            e.target.focus(); //这里就能起作用。不知为毛

            var me = this;
            selectPhoto(9);// 调用app选择图片
            registerHandler('getPhotoFromApp', function( data ){
                var now_state = me.state.dealImgList,
                    dt = data;
                dt.indexOf(',') != -1 && dt.split(',').map( function ( item ) {
                    now_state.unshift(item);
                });
                dt.indexOf(',') == -1 && now_state.unshift(dt);

                if ( now_state.length > 9 ) {
                    appAlert('最多只能上传9张图片!');
                    return;
                }
                me.setState({
                    dealImgList: now_state
                });
            });
        },
        deleteImg(e) {
            let $node = $(e.target),
                $img = $node.siblings('img'),
                imgList = this.state.dealImgList;

            for(let i = 0; i < imgList.length; i++) {
                let img = imgList[i];
                if(img == $img.attr('src')) {
                    imgList.splice(i,1);
                    break;
                }
            }

            this.setState({
                dealImgList: imgList
            });

        },
        // 点击遮罩层隐藏弹出层
        _hideBottomForm: function ( belong ) {
            belong == 'form' && this.setState({
                formVisible: '',
                formConVisible: ''
            });
            belong == 'layer' && this.setState({
                layerVisible: '',
                layerConVisible: ''
            });
            belong == 'helper' && this.setState({
                selectVisible: '',
                selectConVisible: ''
            });
            belong == 'reviewer' && this.setState({
                reviewerVisible: '',
                reviewerConVisible: ''
            });
        },
        // 更新进度
        _updateTaskProcess: function ( cb ) {
            var me = this;

            ajax({
                url: apiUrl + api.getdetail,
                data: {
                    staffId: oldId,
                    orderId: orderId
                },
                headers: {
                    openId:getUrlParam('openId'),
                },
            },
            function (data) {
                //var dt = data,
                //   eventList = dt.eventProcessList;
                //使用最新的wfTaskId
                //	me.state.currTask = eventList[eventList.length - 1];
                //alert(me.state.currTask.wfTaskId);
                cb && cb( data );
           });
        },

        // 更新整个组件
        _updateAllDt: function () {
            ajax({
                data: {
                    loginid: lf.userInfo.loginid,
                    orderId: orderId
                }
            }, "workInfoAction!findWorkinfoByOrdercode.action", function cb ( data ) {
                this.setState({
                    status: data.status,
                    allDt: data
                });
            }.bind(this));
        },
        /**
         * levy 不想写重复的代码!
         * @param me 前面要有 var me = this;这句话。me指的是文件里的RC出来的变量
         * @param dt
         */
        updateStateByLevy: function(me,dt){
            var eventList = dt.eventProcessList;
            me.state.latestWfTaskId = eventList[eventList.length - 1].wfTaskId;

            lf.bridgeJs.doLoading(false);
            me.setState({
                formConVisible: '',
                footerBtnVisible: 'ele-hide',
                allDt: dt,
                taskProcessData: eventList,
                //使用最新的wfTaskId
            });
            //alert(me.state.latestWfTaskId);
        },

        _setFocusFlagHandler: function () {// 设置input聚焦
            this.setState({
                focusFlag: 0
            });
        },
        _: function ( ) {// 设置input失焦
            if ( this.state.focusFlag ) {
                return ;
            }
            //// 使textarea失去焦点, 请使用utils的代码
            //var fakeInput=document.createElement('input');
            //fakeInput.setAttribute('type','text');
            //fakeInput.setAttribute('style','border:none;background:#fff;position:absolute;left:-9999px;bottom:0;line-height:1px;height:1px;');
            //document.body.appendChild(fakeInput);
            //setTimeout(function() {
            //    fakeInput.focus();
            //    setTimeout(function() {
            //        document.body.removeChild(fakeInput);
            //    }, 10);
            //}, 10);
            this.setState({
                focusFlag: 1
            });
        }
    });

    getUser( function ( userInfo ) {
        lf.bridgeJs.setTitle('工单详情')

        ajax({
            url: apiUrl + api.getdetail,
            data: {
                orderId: orderId,
                staffId: oldId,
            },
            headers: {
                openId:getUrlParam('openId'),
            },
            success:function( data ) {
            console.log(data)
            //status 1:退回/派工,2:退回/办理,3:退回/审核,4:撤回,0:没有按钮 status={data.status}
            r.render(
                <TaskProcessCon
                    dt={data}
                    status= {data.status}
                    title="工单信息" />,
                document.getElementById('root')
            )
        }});
    });

});